//
//  AppDelegate.swift
//  DriverClock
//
//  Created by 童巍 on 17/1/11.
//  Copyright © 2017年 童巍. All rights reserved.
//

import UIKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, BMKGeneralDelegate {

    var window: UIWindow?
    var _mapManager: BMKMapManager?

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        UIApplication.shared.setStatusBarStyle(UIStatusBarStyle.lightContent, animated: false)
        _mapManager = BMKMapManager()
        // 如果要关注网络及授权验证事件，请设定generalDelegate参数
//        let ret = _mapManager?.start("nsyY97z7cHu9MAKBMuWwDHiVAVpoduAe", generalDelegate: self)
        let ret = _mapManager?.start("hhyPxIG0vPLg5Na7mBcgDwyvTS9feS7H", generalDelegate: self)        
        if ret == false {
            NSLog("manager start failed!")
        }
        if (UserDefaults.standard.value(forKey: "ISLOGIN") == nil){
           UserDefaults.standard.set(false, forKey: "ISLOGIN")
        }
        if (UserDefaults.standard.value(forKey: "ISLOGIN") as? Bool)! {
            let storyboard = UIStoryboard.init(name: "Main", bundle: nil)
            let vc = storyboard.instantiateViewController(withIdentifier: "mainNavi")
            self.window?.rootViewController = vc
            self.window?.makeKeyAndVisible()
            
        }
        
        
        
        return true
    }

    func applicationWillResignActive(_ application: UIApplication) {
        // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
        // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
    }

    func applicationDidEnterBackground(_ application: UIApplication) {
    
        NotificationCenter.default.post(name: NSNotification.Name(rawValue: "EnterBackground"), object: self)


    }

    func applicationWillEnterForeground(_ application: UIApplication) {
         NotificationCenter.default.post(name: NSNotification.Name(rawValue: "EnterForeground"), object: self)
    }

    func applicationDidBecomeActive(_ application: UIApplication) {
        // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
    }

    func applicationWillTerminate(_ application: UIApplication) {
        // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
    }


}

